<?php
require_once("includes/pagetop.php");



if(isset($_POST['Entertainment'])&& count($_POST['Entertainment'])>0 && isset($_POST['Entertainment']['title']) && trim($_POST['Entertainment']['title'])!="")
{
	$data= $_POST['Entertainment'];
    
    $filename="";
	
    $msg_error="";
    
    
    if($_FILES['entertainment_photo']['name']!="" && isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0)
    {
        include_once "thumb.php";
        if($_FILES['entertainment_photo']['type']=="image/jpeg" || $_FILES['entertainment_photo']['type']=="image/gif" || $_FILES['entertainment_photo']['type']=="image/png" || $_FILES['entertainment_photo']['type']=="image/jpg" || $_FILES['entertainment_photo']['type']=="image/JPEG" || $_FILES['entertainment_photo']['type']=="image/GIF" || $_FILES['entertainment_photo']['type']=="image/PNG" || $_FILES['entertainment_photo']['type']=="image/JPG")
        {
            list($width, $height) = getimagesize($_FILES['entertainment_photo']["tmp_name"]);
            $thumbfolder_val="uploads/entertainments/thumbs/";
            $folder_val="uploads/entertainments";
            if(!file_exists($folder_val))
            {
				mkdir($folder_val,0777);
			}
            
            $folder_val=$folder_val."/";
            $newfilename="";

            $newfilename=$_FILES['entertainment_photo']['name'];
            
            $tempfilepath=$folder_val.time()."_".$newfilename;

            $path=$folder_val.$newfilename;

            
            if(file_exists($path))

            {

				$filenamearr=explode(".",$newfilename);

                

                $newfilename="";

                

                for($i=0;$i<count($filenamearr)-1;$i++)

                {

                    $newfilename=$newfilename.$filenamearr[$i].".";

                }

                $newfilename=substr($newfilename,0,strlen($newfilename)-1);

                $newfilename=$newfilename."_".time().".".$filenamearr[count($filenamearr)-1];

                $path=$folder_val.$newfilename;

			}

            
            //die(" size : ".$width."  height ".$height);
            if(intval($width)>=166 && intval($height)>=116)
            {
                
                if($_FILES['entertainment_photo']['size']<=1048576)
                {
    
                    $move= move_uploaded_file($_FILES['entertainment_photo']['tmp_name'], $tempfilepath);
    
                    if($move)
    
                    {
                        createThumbsforProfiles_widthequal_Transparent($tempfilepath,$path,166,116);
                        
                        $thumbfolder_val=$thumbfolder_val.$newfilename;
    
                        createThumbsforProfiles_widthequal_Transparent($path,$thumbfolder_val,100,75);
    
                        $filename=$newfilename;
                        
                        unlink($tempfilepath);
                    }
    
                    
    
                }
    
                else
    
                {
    
                    
                    $msg_error="Image size should be less than or equal to 1MB";
                    $msgerrtype=1;
                }
            }
        	else
            {
                $msg_error="Image width & height should be greater than 166px & 116px repectively.";
                $msgerrtype=1;
            }

        }
		else
		{
			$msg_error="Entertainment image extension should be one of the (jpg,jpeg,png,gif)";
            $msgerrtype=1;
		}    
    }
    else
    {
		$msg_error="Image is not found!";
        $msgerrtype=1;
	}
    
    if(!(strpos($data['link'],"http://")>=0))
    {
        $data['link']="http://".$data['link'];
    }
    
    
    if($_FILES['entertainment_photo']['name']!="" && trim($filename)=="")
    {
        $msg_error="There is no record added due to : ".$msg_error;
        $msgerrtype=1;
    }
    else
    {
        $data["image_url"]=$filename;
		$check_query=$pdodbobj->fetch_array($pdodbobj->query("select id from af_entertainments where title=:title and type=:type",array("title"=>$data['title'],"type"=>$data['type'])));
        
		if(count($check_query)==0)
		{
		    $insertqry="insert into af_entertainments set type=:type,title=:title,link=:link,image_url=:imgurl,small_description=:description,avg_rating=0,total_pics=0,status='Inactive',added_by='".$_SESSION['Allyfolio_User_ID']."',last_modified_by='".$_SESSION['Allyfolio_User_ID']."',added_date='".time()."',last_modified_date='".time()."'";
            $pdodbobj->query($insertqry,array(":title"=>$data['title'],":type"=>$data["type"],":link"=>$data['link'],":imgurl"=>$data['image_url'],":description"=>$data["small_description"]));
            
            if($pdodbobj->affectedrows>0)
			{
			 	$msg_success="Entertainment Link added successfully.";
			}
			else
			{
				$msg_error="There is no record added.";
                $msgerrtype=1;
			}
			
		}
		else
		{
			$msg_error="There is already one record exists for given entertainment name in selected entertainment type.";
            $msgerrtype=1;
            if(file_exists($path))
            {
                unlink($path);
            }
            if(file_exists($thumbfolder_val))
            {
                unlink($thumbfolder_val);
            }
		}
    }
	
}
$noofappsloadpermoreclick=1;
$nooffmbydefault=4;
?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<title>AllyFolio | Entertainments </title>
<link href="css/style.css" rel="stylesheet" type="text/css" media="all"  />
<script src="js/general.js"></script>
<script src="js/functions.js"></script>

<link rel="stylesheet" href="alertify/themes/alertify.core.css" />
<link rel="stylesheet" href="alertify/themes/alertify.default.css" id="toggleCSS" />
<script src="alertify/lib/alertify.min.js"></script>	
<script src="js/jquery1.10.2.min.js"></script>

<script type="text/javascript" src="js/jquery_1.9.0_min.js"> </script>
<script type="text/javascript" src="js/script.js"></script>

<script src="js/jquery_raty.js"></script>

</head>

<body>

	<div id="main_wrapper">
    <?php
    $pageheading="Entertainment";
    require_once("includes/header.php");
    
    
    $condition=array();
    $query="select id,title,image_url,link,small_description,total_pics,avg_rating from af_entertainments where status='Active' ";
    $serachcond="";
    
    $fmquery=$query." and type='FM' ";
    
    $moviequery=$query." and type='Movie' ";
    
    $tvquery=$query." and type='TV' ";
    
    if(isset($_POST['istrend']) && $_POST['istrend']>0)
    {
        $fmquery.=" order by total_pics desc,added_date desc limit ".$nooffmbydefault;
        $moviequery.=" order by total_pics desc,added_date desc limit ".$noofappsloadpermoreclick;
        $tvquery.=" order by total_pics desc,added_date desc limit ".$noofappsloadpermoreclick;
    }
    else
    {
        $fmquery.=" order by added_date desc limit ".$nooffmbydefault;
        $moviequery.=" order by added_date desc limit ".$noofappsloadpermoreclick;
        $tvquery.=" order by added_date desc limit ".$noofappsloadpermoreclick;
    }
    
    $fminfo=$pdodbobj->fetch_array($pdodbobj->query($fmquery,$condition));
    
    $tvinfo=$pdodbobj->fetch_array($pdodbobj->query($tvquery,$condition));
    
    $movieinfo=$pdodbobj->fetch_array($pdodbobj->query($moviequery,$condition));
    
    
    ?>
    
    
    <!--=================Body Contain Start=======================-->
    <div class="wrapper">
    	<div class="header">
        		<div class="contain-wrap" style="margin-top:30px;">
     
			<div style="color:#000; font-size:32px; text-align:center; padding-bottom:30px;" class="creat_txt">Connect to These Stations & Play Music Which You Like
            <?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0 && isset($loggedinuserdetails[0]['Is_Celebrity']) && $loggedinuserdetails[0]['Is_Celebrity']==1){  ?><br />(<a href="javascript:void(0);" onclick="document.getElementById('popup_content').style.display='';showpopup();">Upload Yours</a>)<?php } ?>
            </div>
			<div class="buseness_head2">
			
				
				<ul class="inro_btn2">
					<li><a href="javascript:void(0);" <?php if(isset($_POST['istrend']) && $_POST['istrend']==0){ echo "style='color:#D4EFFC;'"; } ?> onclick="return loaddatabyorder(0);">General</a></li>
					
					<li><a href="javascript:void(0);"  <?php if(isset($_POST['istrend']) && $_POST['istrend']==1){ echo "style='color:#D4EFFC;'"; } ?> onclick="return loaddatabyorder(1);">Trends</a></li>
				</ul>
                
			</div>
     
            <form name="entertainmentform" method="post" enctype="multipart/form-data">
			<div class="ent">
				<table width="100%" border="0">
                  <tr>
                    <td valign="top">
                		<table style="width: 100%;" id="mtable">
                            <tr>
                                <td style="text-align: center;height:35px;vertical-align: top;">
                                    <span><strong>Movies</strong></span>
                                </td>
                            </tr>
                            <?php
                            $starcount=1;
                            if(count($movieinfo)>0)
                            {
                                for($j=0;$j<count($movieinfo);$j++)
                                {
                                    if(!(strstr($movieinfo[$j]['link'],"http://")) && trim($movieinfo[$j]['link'])!='')
                                    {
                                        $movieinfo[$j]['link']="http://".$movieinfo[$i]['link'];
                                    }
                                ?>
                                        
                            <tr>
                                <td>
                                    <div class="chanel_pic">
                                        <a href="javascript:void(0);" <?php  if(trim($movieinfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $movieinfo[$j]['link']; ?>');" <?php } ?> >
                                            <img src="<?php echo "uploads/entertainments/".$movieinfo[$j]['image_url']; ?>" width="166px" height="116px" />
                                        </a>
                                	</div>
                            		<div class="clearfix"></div>
                            		<div class="star" style="padding-left: 5px;">
                						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($movieinfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $movieinfo[$j]['link']; ?>');" <?php } ?> ><?php echo $movieinfo[$j]['title']; ?></a></p>
                						<p class="ret">Rating<div id="star_m_<?php echo $starcount; ?>"></div></p>
                                        <input type="hidden" name="entertainid_m_<?php echo $starcount; ?>" id="entertainid_m_<?php echo $starcount; ?>" value="<?php echo $movieinfo[$j]['id']; ?>" />
                                        <input type="hidden" name="avgrating_m_<?php echo $starcount; ?>" id="avgrating_m_<?php echo $starcount; ?>" value="<?php echo round($movieinfo[$j]['avg_rating']); ?>" />
                                        <p class="ret"><a href="javascript:void(0);" onclick="updatePickcounter(<?php echo $movieinfo[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $movieinfo[$j]['link']; ?>',<?php echo $starcount; ?>,'m');">pick</a><span class="num" id="pick_m_<?php echo $starcount; ?>"><?php echo $movieinfo[$j]['total_pics']; ?></span></p>
                						<p class="ret"><?php echo $movieinfo[$j]['small_description']; ?></p>
                						
                					</div>
                                </td>
                            </tr>
                            <?php
                                $starcount++;
                                }
                            }
                            else
                            {
                                ?>
                                <tr>
                                    <td style="vertical-align: top;">
                                        <span style="color: red;">
                                            No Movie Link Found...
                                        </span>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                        </table>
                        <?php 
                        if(count($movieinfo)>0)
                        {
                        ?>
                        <div class="more2">
                             <a href="javascript:void(0);" id="appmorelinkm" onclick="return getmoreapps('m');">More........</a>
                        </div>
                        <?php
                        }
                        ?>
                    </td>
                	<td valign="top">
                	
                		<div class="mid">
                			<table width="99%" border="0" style="margin-top:45px;" id="ftable">
                				<?php
                                $k=0;        
                                $starcount1=1;
                                if(count($fminfo)>0)
                                {
                                    for($j=0;$j<count($fminfo);$j=$j+2)
                                    {
                                        if(!(strstr($fminfo[$j]['link'],"http://")) && trim($fminfo[$j]['link'])!='')
                                        {
                                            $fminfo[$j]['link']="http://".$fminfo[$i]['link'];
                                        }
                                        
                                        if(($j)%2==0)
                                        {
                                            $class1="2";
                                            $class2="";
                                        }
                                        if(($j)%4==0)
                                        {
                                            $class1='';
                                            $class2='2';
                                        }
                                            ?>
                                                <tr>
                            					<td style="border-right:1px solid #ccebef" >
                            						<div class="chanel_pic<?php echo $class1; ?>">
                                                        <a href="javascript:void(0);" <?php  if(trim($fminfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $fminfo[$j]['link']; ?>');" <?php } ?> >
                                                            <img src="<?php echo "uploads/entertainments/".$fminfo[$j]['image_url']; ?>" width="166px" height="116px" />
                                                        </a>
                            						</div>
                            						<div class="star<?php echo $class1; ?>" <?php if($class1==2){ echo "style='float:right;'"; } ?> >
                            						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($fminfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $fminfo[$j]['link']; ?>');" <?php } ?> ><?php echo $fminfo[$j]['title']; ?></a></p>
                            						<p class="ret">Rating<div id="star_f_<?php echo $starcount1; ?>"></div></p>
                                                         <input type="hidden" name="entertainid_f_<?php echo $starcount1; ?>" id="entertainid_f_<?php echo $starcount1; ?>" value="<?php echo $fminfo[$j]['id']; ?>" />
                                                         <input type="hidden" name="avgrating_f_<?php echo $starcount1; ?>" id="avgrating_f_<?php echo $starcount1; ?>" value="<?php echo round($fminfo[$j]['avg_rating']); ?>" />
                            						<p class="ret"><a href="javascript:void(0);" onclick="updatePickcounter(<?php echo $fminfo[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $fminfo[$j]['link']; ?>',<?php echo $starcount1; ?>,'f');">pick</a><span class="num" id="pick_f_<?php echo $starcount1; ?>"><?php echo $fminfo[$j]['total_pics']; ?></span></p>
                            						<p class="ret"><?php //echo $fminfo[$j]['small_description']; ?></p>
                            						
                            						</div>	
                            						<div class="clearfix"></div>
                            						<span class="out" style="float: <?php if($class1==2){ echo "right;padding-right:5px;"; }else{ echo "left"; } ?>;"><?php echo $fminfo[$j]['small_description']; ?></span>
                            					</td>
                                                <?php
                                                $starcount1++;
                                                $j++;
                                                if($j<count($fminfo))
                                                {
                                                ?>
                            					<td>
                            						<div class="chanel_pic<?php echo $class2; ?>">
                            						<a href="javascript:void(0);" <?php  if(trim($fminfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $fminfo[$j]['link']; ?>');" <?php } ?> >
                                                            <img src="<?php echo "uploads/entertainments/".$fminfo[$j]['image_url']; ?>" width="166px" height="116px" />
                                                        </a>
                            						</div>
                            						<div class="star<?php echo $class2; ?>" <?php if($class2==2){ echo "style='float:right;'"; } ?> >
                            						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($fminfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $fminfo[$j]['link']; ?>');" <?php } ?> ><?php echo $fminfo[$j]['title']; ?></a></p>
                            						<p class="ret">Rating<div id="star_f_<?php echo $starcount1; ?>"></div></p>
                                                         <input type="hidden" name="entertainid_f_<?php echo $starcount1; ?>" id="entertainid_f_<?php echo $starcount1; ?>" value="<?php echo $fminfo[$j]['id']; ?>" />
                                                         <input type="hidden" name="avgrating_f_<?php echo $starcount1; ?>" id="avgrating_f_<?php echo $starcount1; ?>" value="<?php echo round($fminfo[$j]['avg_rating']); ?>" />
                            						<p class="ret"><a href="javascript:void(0);" onclick="updatePickcounter(<?php echo $fminfo[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $fminfo[$j]['link']; ?>',<?php echo $starcount1; ?>,'f');">pick</a><span class="num" id="pick_f_<?php echo $starcount1; ?>"><?php echo $fminfo[$j]['total_pics']; ?></span></p>
                            						<p class="ret"><?php //echo $fminfo[$j]['small_description']; ?></p>
                            						
                            						</div>	
                            						<div class="clearfix"></div>
                            						<span class="out" style="float: <?php if($class2==2){ echo "right;padding-right:5px;"; }else{ echo "left"; } ?>;"><?php echo $fminfo[$j]['small_description']; ?></span>                            					</td>
                                                </td>
                                                <?php
                                                }
                                                $j--;
                                                ?>     
                            				</tr>
                                         <?php   
                                        if(($j+2)<count($fminfo))
                                        {
                                            ?>
                                            <tr>
                                                <td style="padding-left: 20px;padding-right:20px;padding:10px auto;height:30px;">
                                                    <div style="border-top: 1px solid #999;"></div>
                                                </td>
                                                <td style="padding-left: 20px;padding-right:20px;padding:10px auto;">
                                                    <div style="border-top: 1px solid #999;"></div>
                                                </td>
                                            </tr>
                                            <?php
                                        }
                                        $starcount1++;
                                    }
                               }
                               else
                               {
                                    ?>
                                    <tr>
                                        <td colspan="2">
                                            <span style="color: red;">
                                                No Movie Link Found...
                                            </span>
                                        </td>
                                    </tr>
                                    <?php
                               }
                               ?>             
                			</table>
                            <?php 
                                if(count($tvinfo)>0)
                                {
                                ?>
                                <div class="more2">
                                     <a href="javascript:void(0);" id="appmorelinkf" onclick="return getmoreapps('f');">More........</a>
                                </div>
                                <?php
                                }
                                ?> 		
                            </div>
                		
                	</td>
                    <td valign="top">
                		<table style="width: 100%;" id="ttable">
                            <tr>
                                <td style="text-align: center;height:35px;vertical-align: top;">
                                    <span><strong>TV</strong></span>
                                </td>
                            </tr>
                            <?php
                            $starcount2=1;
                            if(count($tvinfo)>0)
                            {
                                for($j=0;$j<count($tvinfo);$j++)
                                {
                                    if(!(strstr($tvinfo[$j]['link'],"http://")) && trim($tvinfo[$j]['link'])!='')
                                    {
                                        $tvinfo[$j]['link']="http://".$tvinfo[$i]['link'];
                                    }
                                ?>
                                        
                            <tr>
                                <td>
                                    <div class="chanel_pic">
                                        <a href="javascript:void(0);" <?php  if(trim($tvinfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $tvinfo[$j]['link']; ?>');" <?php } ?> >
                                            <img src="<?php echo "uploads/entertainments/".$tvinfo[$j]['image_url']; ?>" width="166px" height="116px" />
                                        </a>
                                	</div>
                            		<div class="clearfix"></div>
                            		<div class="star2" style="padding-right: 5px;float:right;">
                						<p class="ch_name"><a href="javascript:void(0);" <?php  if(trim($tvinfo[$j]['link'])!='http://'){ ?> onclick="window.open('<?php echo $tvinfo[$j]['link']; ?>');" <?php } ?> ><?php echo $tvinfo[$j]['title']; ?></a></p>
                						<p class="ret">Rating<div id="star_t_<?php echo $starcount2; ?>"></div></p>
                                        <input type="hidden" name="entertainid_t_<?php echo $starcount2; ?>" id="entertainid_t_<?php echo $starcount2; ?>" value="<?php echo $tvinfo[$j]['id']; ?>" />
                                        <input type="hidden" name="avgrating_t_<?php echo $starcount2; ?>" id="avgrating_t_<?php echo $starcount2; ?>" value="<?php echo round($tvinfo[$j]['avg_rating']); ?>" />
                                        <p class="ret"><a href="javascript:void(0);" onclick="updatePickcounter(<?php echo $tvinfo[$j]['id']; ?>,<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>,'<?php echo $tvinfo[$j]['link']; ?>',<?php echo $starcount2; ?>,'t');">pick</a><span class="num" id="pick_t_<?php echo $starcount2; ?>"><?php echo $tvinfo[$j]['total_pics']; ?></span></p>
                						<p class="ret"><?php echo $tvinfo[$j]['small_description']; ?></p>
                						
                					</div>
                                </td>
                            </tr>
                            <?php
                                $starcount2++;
                                }
                            }
                            else
                            {
                                ?>
                                <tr>
                                    <td style="vertical-align: top;">
                                        <span style="color: red;">
                                            No TV Link Found...
                                        </span>
                                    </td>
                                </tr>
                                <?php
                            }
                            ?>
                        </table>
                        <?php 
                        if(count($tvinfo)>0)
                        {
                        ?>
                        <div class="more2">
                             <a href="javascript:void(0);" id="appmorelinkt" onclick="return getmoreapps('t');">More........</a>
                        </div>
                        <?php
                        }
                        ?>
                    </td>
                  </tr>

  
            </table>
                <input type="hidden" name="istrend" id="istrend" value="<?php if(isset($_POST['istrend']) && trim($_POST['istrend'])!=""){ echo $_POST['istrend']; }else{ echo "0"; } ?>" />
                <input type="hidden" name="mcount" id="mcount" value="<?php if(isset($_POST['mcount']) && trim($_POST['mcount'])!=""){ echo $_POST['mcount']; }else{ echo $starcount; } ?>" />
                <input type="hidden" name="fcount" id="fcount" value="<?php if(isset($_POST['fcount']) && trim($_POST['fcount'])!=""){ echo $_POST['fcount']; }else{ echo $starcount1; } ?>" />
                <input type="hidden" name="tcount" id="tcount" value="<?php if(isset($_POST['tcount']) && trim($_POST['tcount'])!=""){ echo $_POST['tcount']; }else{ echo $starcount2; } ?>" />
                
                <input type="hidden" name="gamesscore" id="gamesscore" value="0" />
                <input type="hidden" name="gameid" id="gameid" value="0" />
                <input type="hidden" name="loggedinuserid" id="loggedinuserid" value="<?php if(isset($_SESSION['Allyfolio_User_ID']) && $_SESSION['Allyfolio_User_ID']>0){ echo $_SESSION['Allyfolio_User_ID']; }else{ echo "0"; } ?>" />
			</div>
            
            <div class="clearfix"></div>
            <div id="toPopup"> 
    	
                <div class="close"></div>
                <div id="popup_content" >  
                    <div class="forgetPass" style="width:600px;">
                    
                      <h3>Upload Entertainment</h3>
                      <?php
                    if(isset($errormsg) && $errormsg!="")
                    {
                        ?>
                        <div class="errormsg" ><?php echo $errormsg; ?><br /><br /></div>
                        <?php
                    }
                    ?>
                    <table style="width:600px">
                          <tr>
                            <td style="width:25%;"><label>Link Title<span style="color: red;">*</span></label></td>
                            <td style="width:75%;height:35px;"><input type="text" class="upload_frm" id="title" name="Entertainment[title]" placeholder="Entertainment Link Title" /></td>
                          </tr> 
                          <tr>
                              <td style="width:25%;"><label>Link Type<span style="color: red;">*</span></label></td>
                              <td style="width:75%;height:35px;"><select class="upload_frm" id="type" name="Entertainment[type]">
                                    <option value=""> Select Entertainment Link Type </option>
                                    <option value="TV" <?php if(isset($data['type']) && $data['type']!=Null && $data['type']=="TV")echo "selected"; ?> >TV Channel</option>
                                    <option value="FM" <?php if(isset($data['type']) && $data['type']!=Null && $data['type']=="FM")echo "selected"; ?> >FM Radio</option>
                                    <option value="Movie" <?php if(isset($data['type']) && $data['type']!=Null && $data['type']=="Movie")echo "selected"; ?> >Movie Link</option>
                              </select>
                              </td>
                          </tr>
                          <tr>
                              <td style="width:25%;"><label>Link URL<span style="color: red;">*</span></label></td>
                              <td style="width:75%;height:35px;">http://<input type="text" name="Entertainment[link]" id="link" class="upload_frm" placeholder="Entertainment Link URL" style="width: 89%;" /></td>
                          </tr>
                          <tr>
                              <td style="width:25%;"><label>Image<span style="color: red;">*</span></label></td>
                              <td style="width:75%;height:35px;"><input type="file" name="entertainment_photo" id="entertainment_photo" placeholder="Entertainment Link Image" /><br />
                                * Image width & height should be greater than 166px & 116px repectively.
                              </td>
                          </tr>
                          <tr>
                              <td style="width:25%;"><label>Small Description<span style="color: red;">*</span></label></td>
                              <td style="width:75%;height:35px;"><input type="text" name="Entertainment[small_description]" id="smalldescription" class="upload_frm" placeholder="Entertainment Small Description" /></td>
                          </tr>
                          <tr><td colspan="2" style="text-align: center;height:40px;">    
                            <div class="btns" style="text-align: center;"><input type="submit" value="Submit" id="forgotpassbtn" /> &nbsp; <input type="button" value="Cancel" class="simplebutton" onclick="return disablePopup();" /></div>
                          </td></tr>
                        </table>
                      </div>        
                </div>
            
            </div>
        	<div class="loader"></div>
   	<div id="backgroundPopup"></div>
    
            </form>
            </div>
            
            <div class="clearfix"></div>
            </div>
            </div>
            
           
    <div class="clearfix"></div>
    <!--=================Body Contain end=======================-->
    </div>
    
    <?php
    require_once("includes/footer.php");
?>
<script lang="javascript">
//<![CDATA[

var rateclickid=0;
var universeappflag=1;

$(document).ready(function(){

  $(".close").click(function(){

    disablePopup();

  });
});

function disablePopup()
{
    $("#toPopup, #backgroundPopup").hide("slow");
}

function changerating(id,value,type)
{
    var readonlyflag=false;
    if(document.getElementById('loggedinuserid').value=="0")
    {
        readonlyflag=false;
    }
    
    for(var i=1;i<parseInt(document.getElementById(type+'count').value);i++)
    {
        if(document.getElementById('star_'+type+'_'+i))
        {
            document.getElementById('star_'+type+'_'+i).innerHTML="";
        }
    }
    
    for(var i=1;i<parseInt(document.getElementById(type+'count').value);i++)
    {
        if(document.getElementById('star_'+type+'_'+i))
        {
            if(id==i)
            {
                $("#star_"+type+'_'+i).raty({
                  score: value,  
                  click: function(score,evt) {
                    document.getElementById('gamesscore').value=score;
                    var starid=this.id;
                    typeidarr=starid.split("_");
                    starid=starid.replace("star","");
                    
                    document.getElementById('gameid').value=document.getElementById('entertainid'+starid).value;
                    rateclickid=typeidarr[2];
                    saveRating(typeidarr[1]);
                  }
                });
            }
            else
            {
                avgrating=parseInt(document.getElementById('avgrating_'+type+'_'+i).value);
                $("#star_"+type+'_'+i).raty({
                  score: avgrating,
                  readOnly: readonlyflag,  
                  click: function(score,evt) {
                    document.getElementById('gamesscore').value=score;
                    var starid=this.id;
                    typeidarr=starid.split("_");
                    starid=starid.replace("star","");
                    
                    document.getElementById('gameid').value=document.getElementById('entertainid'+starid).value;
                    rateclickid=typeidarr[2];
                    saveRating(typeidarr[1]);
                  }
                });
            }
        }
    }
}

function getmoreapps(type)
{
    if(universeappflag==1)
    {
        nextcount=1;
        disableLink('appmorelink'+type);
        if(type=="f")
        {
            nextcount=<?php echo $nooffmbydefault; ?>;
        }
        else if(type=="m")
        {
            nextcount=<?php echo $noofappsloadpermoreclick; ?>;
        }
        else if(type=="t")
        {
            nextcount=<?php echo $noofappsloadpermoreclick; ?>;
        }
        
        $.ajax({
          cache:false,  
          async:false,
    	  url: "ajax_search/ajax_manageentapps.php?action=getapps&userid="+trim(document.getElementById('loggedinuserid').value)+"&currentcount="+trim(document.getElementById(type+'count').value)+"&nextcount="+nextcount+"&istrend="+trim(document.getElementById('istrend').value)+"&type="+type,
    	  success: function( data ) {
    	    
            var dataarr=data.split("~:~");
            if(trim(data)!="")
            {
                document.getElementById(type+'table').innerHTML=document.getElementById(type+'table').innerHTML+trim(dataarr[0]);
                document.getElementById(type+'count').value=dataarr[1];
            }
            else
            {
                alertify.alert("There is no more record found...");
                return false;
            }
            changerating(0,0,type);
    	  }
    	});
    }
    
}

function saveRating(type)
{
    if(document.getElementById('loggedinuserid').value=="0")
    {
        changerating(rateclickid,parseInt(document.getElementById('avgrating_'+type+'_'+rateclickid).value),type);
        alertify.alert('Please login first to rate the entertainment link.');
        return false;
    }
    else
    {
        $.ajax({
          cache:false,  
    	  url: "ajax_search/ajax_manageentapps.php?action=saverating&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+trim(document.getElementById('gameid').value)+"&starrating="+parseInt(trim(document.getElementById('gamesscore').value)),
    	  success: function( data ) {
    	    if(data=="Already")
            {
                changerating(rateclickid,parseInt(document.getElementById('avgrating_'+type+'_'+rateclickid).value),type);
                alertify.alert('You have already rated this entertainment link.');
                return false;
            }
            else if(parseInt(data)>=0)
            {
                alertify.alert("You have successfully rated this entertainment link.");
                document.getElementById('avgrating_'+type+'_'+rateclickid).value=trim(parseInt(data).toString());
                changerating(rateclickid,parseInt(data),type);
                return false;
            }
            else
            {
                alertify.alert("There is an error in updating entertainment link rating.");
                return false;
            }
    	  }
    	});
        
    }
}

function updatePickcounter(appid,userid,linkval,starcountid,type)
{
    if(userid==0)
    {
        alertify.alert('Please login first to pick the entertainment link.');
        return false;
    }
    else
    {
        $.ajax({
          cache:false,  
    	  url: "ajax_search/ajax_manageentapps.php?action=pickupdate&userid="+trim(document.getElementById('loggedinuserid').value)+"&appid="+appid,
    	  success: function( data ) {
    	    //console.log(data);
    	    //alert(data);
    	    if(parseInt(data)>=0)
            {
                document.getElementById('pick_'+type+'_'+starcountid).innerHTML=trim(parseInt(data).toString());
                //window.open(linkval);
                return false;
            }
            else
            {
                alertify.alert("There is an error in picking the entertainment link.");
                return false;
            }
    	  }
    	});
    }
}

function loaddatabyorder(trendorder)
{
    document.getElementById("istrend").value=trendorder;
    document.entertainmentform.submit();
}

function showuploadform()
{
    if(document.getElementById('loggedinuserid').value=="0")
    {
        alertify.alert("Please login first to add your entertainment link.");
    }
    else
    {
        document.getElementById('uploadform').style.display='';    
    }
    
}

$("#forgotpassbtn").click(submitUpload);
     
function submitUpload()
{
    if(trim(document.getElementById("title").value)=="")
	{
		alertify.alert("Entertainment Link title field is required!");
		document.getElementById("title").focus();
		return false;
	}
	else if(trim(document.getElementById("type").value)=="")
	{
		alertify.alert("Entertainment Link Type field is required!");
		document.getElementById("type").focus();
		return false;
	}
    else if(trim(document.getElementById("link").value)=="")
	{
		alertify.alert("Entertainment Link URL field is required!");
		document.getElementById("link").focus();
		return false;
	}
    else if(trim(document.getElementById("entertainment_photo").value)=="")
	{
		alertify.alert("Entertainment Link image field is required!");
		document.getElementById("entertainment_photo").focus();
		return false;
	}
    else if(trim(document.getElementById("smalldescription").value)=="")
	{
		alertify.alert("Entertainment Link small description of maximum 50 characters is required!");
		document.getElementById("smalldescription").focus();
		return false;
	}
    else
    {
        document.uploadfrm.submit();
    }
}

<?php
if(isset($msg_success) && $msg_success!="")
{
    ?>
    alertify.alert("<?php echo $msg_success; ?>");
    <?php
}

if(isset($msg_error) && $msg_error!="")
{
    ?>
    alertify.alert("<?php echo $msg_error; ?>");
    <?php
}
?>

changerating(0,0,'t');
changerating(0,0,'f');
changerating(0,0,'m');

<?php
    if(isset($msg_error) && $msg_error!="")
    {
        ?>
        document.getElementById('popup_content').style.display='';
        showpopup();
        <?php
    }
    ?>
    
//]]>
</script>